//
//  TeadcherHeadView.m
//  GC_OC
//
//  Created by lbh on 2022/4/8.
//

#import "TeadcherHeadView.h"

@implementation TeadcherHeadView
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self makeUI];
    }
    return self;
}
#pragma mark --Private
- (void)makeUI{
    self.backgroundColor = RBG(244,244, 244);
    [self addSubview:self.bgView];
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(10);
        make.left.mas_equalTo(5);
        make.right.mas_equalTo(-5);
        make.bottom.mas_equalTo(-10);
    }];
    
    [self.bgView addSubview:self.imageView];
    [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(3);
        make.left.mas_equalTo(15);
        make.width.mas_equalTo(110);
        make.height.mas_equalTo(150);
        make.bottom.mas_equalTo(0);
    }];
    
    [self.bgView addSubview:self.titleLabel];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.imageView.mas_top).offset(10);
        make.left.mas_equalTo(self.imageView.mas_right).offset(18);
    }];
    
//    [self.bgView addSubview:self.sexLabel];
//    [self.sexLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(5);
//        make.left.mas_equalTo(self.titleLabel.mas_left);
//    }];
    
    [self.bgView addSubview:self.descLabel];
    [self.descLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(5);
        make.left.mas_equalTo(self.titleLabel.mas_left);
        make.right.mas_equalTo(-5);
        make.bottom.mas_equalTo(0);
    }];
}
- (NSMutableAttributedString *)createAttributedStr:(NSRange)range withArrtStr:(NSString *)string{
    
    NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:string];
    [AttributedStr addAttribute:NSFontAttributeName
                          value:[UIFont fontWithName:@"PingFangSC-Medium" size:14]
                          range:range];
    [AttributedStr addAttribute:NSForegroundColorAttributeName
                          value:UIColor.blackColor
                          range:range];
    
    return AttributedStr;
}
- (void)setTeachDict:(NSDictionary *)teachDict{
    _teachDict = teachDict;
    NSString *media_image = teachDict[@"teacher_image"];
    NSString *teacher_introduce = teachDict[@"teacher_introduce"];
    if (teacher_introduce) {
        teacher_introduce = [teacher_introduce fk_replaceHtmlTag];
    }
    NSString *name = teachDict[@"teacher_name"];
    NSString *teacher_sex = teachDict[@"teacher_sex"];
    NSString *zLogo = @"logo_nan01";
    if (teacher_sex.intValue == 2) {
        zLogo = @"Logo_nu01";
    }
    media_image = [media_image stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    [self.imageView sd_setImageWithURL:[NSURL URLWithString:media_image] placeholderImage:[UIImage imageNamed:zLogo]];
//    name = [NSString stringWithFormat:@"姓名:%@",name];
//    teacher_sex = [NSString stringWithFormat:@"性别:%@",teacher_sex.intValue ==2?@"女":@"男"];
//    teacher_introduce = [NSString stringWithFormat:@"简介:%@",teacher_introduce];
//
//    self.titleLabel.attributedText = [self createAttributedStr:NSMakeRange(0, 2) withArrtStr:name];
//    self.sexLabel.attributedText = [self createAttributedStr:NSMakeRange(0, 2) withArrtStr:teacher_sex];
//    self.descLabel.attributedText = [self createAttributedStr:NSMakeRange(0, 2) withArrtStr:teacher_introduce];
    self.titleLabel.text = name;
//    self.sexLabel.text = teacher_sex.intValue ==2?@"女":@"男";
    self.descLabel.text = teacher_introduce;
}
#pragma mark --lazy
- (UIView *)bgView{
    if (!_bgView) {
        _bgView = [[UIView alloc]init];
        _bgView.backgroundColor = [UIColor clearColor ];
        [self setUpViewLayer:_bgView];
    }
    return _bgView;
}
- (UIImageView *)imageView{
    if (!_imageView) {
        _imageView = [[UIImageView alloc]init];
        _imageView.layer.masksToBounds = YES;
        _imageView.layer.cornerRadius = 0;
        _imageView.contentMode = UIViewContentModeScaleAspectFill;
//        [self setUpViewLayer:_imageView];
//        CAShapeLayer *maskLayer = [UIView createBezierPath:CGRectMake(0, 0, 130, 170) withRoundingCorners:UIRectCornerTopRight | UIRectCornerBottomRight | UIRectCornerTopLeft | UIRectCornerBottomLeft withRadid:CGSizeMake(5, 5)];
//        _imageView.layer.mask = maskLayer;
    }
    return _imageView;
}
- (void)setUpViewLayer:(UIView *)vie
{
    vie.layer.shadowColor = [[UIColor blackColor] colorWithAlphaComponent:0.8].CGColor;
    vie.layer.shadowOffset = CGSizeMake(0,0);
    vie.layer.shadowOpacity = 0.1;
    vie.layer.shadowRadius = 5;
    vie.layer.cornerRadius = 15;
}
- (UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc]init];
        _titleLabel.font = [UIFont boldSystemFontOfSize:16];
        _titleLabel.textColor = [UIColor colorWithRed:60/255.0 green:65/255.0 blue:69/255.0 alpha:1.0];
        _titleLabel.numberOfLines = UIViewContentModeCenter;
        _titleLabel.text = @"标题";
    }
    return _titleLabel;
}
- (UILabel *)sexLabel{
    if (!_sexLabel) {
        _sexLabel = [[UILabel alloc]init];
        _sexLabel.font = [UIFont boldSystemFontOfSize:16];
        _sexLabel.textColor = [UIColor colorWithRed:60/255.0 green:65/255.0 blue:69/255.0 alpha:1.0];
        _sexLabel.numberOfLines = UIViewContentModeCenter;
        _sexLabel.text = @"女";
    }
    return _sexLabel;
}
- (BZAlertLabel *)descLabel{
    if (!_descLabel) {
        _descLabel = [[BZAlertLabel alloc]init];
        _descLabel.font = [UIFont boldSystemFontOfSize:16];
        _descLabel.textColor = [UIColor colorWithRed:60/255.0 green:65/255.0 blue:69/255.0 alpha:1.0];
        _descLabel.text = @"描述";
        _descLabel.numberOfLines = 0;
        _descLabel.adjustsFontSizeToFitWidth = YES;
       _descLabel.minimumScaleFactor = 0.7;
        _descLabel.verticalAlignment = 0;
    }
    return _descLabel;
}
@end
